/**
 * Created by LC on 2019/11/22
 */
package com.hw.paltfrom.service.system;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwBaseCountycoreMapper;
import com.hw.paltfrom.mapper.HwBaseEnterpriseMapper;
import com.hw.paltfrom.mapper.HwBaseOffsiteMapper;
import com.hw.paltfrom.mapper.HwBaseOverrunstationMapper;
import com.hw.paltfrom.pojo.HwBaseCountycore;
import com.hw.paltfrom.pojo.HwBaseEnterprise;
import com.hw.paltfrom.pojo.HwBaseOffsite;
import com.hw.paltfrom.pojo.HwBaseOverrunstation;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.ResponeResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GisMapService {

    @Autowired
    HwBaseOverrunstationMapper overrunstationMapper;

    @Autowired
    HwBaseCountycoreMapper countycoreMapper;

    @Autowired
    HwBaseOffsiteMapper offsiteMapper;

    @Autowired
    HwBaseEnterpriseMapper enterpriseMapper;

    public Map<String, Object> findOverrun(String overrunCode) {
        HwBaseOverrunstation baseOverrunstation = new HwBaseOverrunstation();
        baseOverrunstation.setfOverruncode(overrunCode);
        baseOverrunstation.setfDeletemark(0);
        baseOverrunstation.setfEnabledmark(1);
        HwBaseOverrunstation info = overrunstationMapper.selectOne(baseOverrunstation);
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,info);
    }

    public Map<String, Object> findOffsite(String areaId) {
        //超限站
        HwBaseCountycore countycore = new HwBaseCountycore();
        countycore.setfAreaid(areaId);
        countycore.setfDeletemark(0);
        countycore.setfEnabledmark(1);
        HwBaseCountycore resultCountyCore = null;
        try {
            resultCountyCore = countycoreMapper.selectOne(countycore);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponeResultUtil.fail(HWSystemCode.DATA_NOTFOUND);
        }
        //非现场
        Wrapper<HwBaseOffsite> offsiteWrapper = new EntityWrapper<>();
        offsiteWrapper.eq("F_AreaId",areaId).eq("F_DeleteMark",0).eq("F_EnabledMark",1);
        List<HwBaseOffsite> hwBaseOffsites = offsiteMapper.selectList(offsiteWrapper);
        Map<String,Object> result = new HashMap<>();
        result.put("resultCountyCore",resultCountyCore);
        result.put("hwBaseOffsites",hwBaseOffsites);
        return result;
    }

    public Map<String, Object> findEnterprise(String areaId) {
        //超限站
        HwBaseCountycore countycore = new HwBaseCountycore();
        countycore.setfAreaid(areaId);
        countycore.setfDeletemark(0);
        countycore.setfEnabledmark(1);
        HwBaseCountycore resultCountyCore = null;
        try {
            resultCountyCore = countycoreMapper.selectOne(countycore);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponeResultUtil.fail(HWSystemCode.DATA_NOTFOUND);
        }
        //源头企业
        Wrapper<HwBaseEnterprise> enterpriseWrapper = new EntityWrapper<>();
        enterpriseWrapper.eq("F_AreaId",areaId).eq("F_DeleteMark",0).eq("F_EnabledMark",1);
        List<HwBaseEnterprise> resultEnterprises = enterpriseMapper.selectList(enterpriseWrapper);
        Map<String,Object> result = new HashMap<>();
        result.put("resultCountyCore",resultCountyCore);
        result.put("resultEnterprises",resultEnterprises);
        return result;
    }
}
